package com.fushenlan.epidemicControl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fushenlan.commons.GeneralResponse;
import com.fushenlan.dto.AllInformationInfoDTO;
import com.fushenlan.dto.PersonalInfoRespDTO;
import com.fushenlan.dto.PersonalStatusCommitReqDTO;
import com.fushenlan.dto.YangPersonalDetailsDTO;
import com.fushenlan.epidemicControl.service.YangManageService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@Api(tags = "阳性居民管理")
@Slf4j
@RestController
@RequestMapping("/yangManage")
public class YangManageController {

    @Autowired
    private YangManageService yangManageService;

    /**
     * 居民最新情况查询
     * @param community  小区
     * @param name  姓名搜索
     * @param status  1-未转运 2-已转运 3-已治愈
     * @param pageSize  每页显示条数
     * @param pagerNum  当前页
     * @return
     */
    @GetMapping("/queryYangPersonal")
    public GeneralResponse<IPage<PersonalInfoRespDTO>> queryYangPersonal(@RequestParam(required = false,value = "community") Long community,
                                                                             @RequestParam(required = false,value = "name") String name,
                                                                             @RequestParam(required = false,value ="status") Integer status,
                                                                             @RequestParam("pageSize") Integer pageSize,
                                                                             @RequestParam("pagerNum") Integer pagerNum) {
        try {
            return yangManageService.queryYangPersonal( community, name, status, pageSize, pagerNum);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 居民最新情况查询

     * @return
     */
    @GetMapping("/queryYangNum")
    public GeneralResponse<AllInformationInfoDTO> queryYangNum() {
        try {
            return yangManageService.queryYangNum();
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 转运治愈登记
     */
    @PostMapping("/personalStatusCommit")
    public GeneralResponse personalStatusCommit(@RequestBody PersonalStatusCommitReqDTO personalStatusCommitReqDTO) {
        try {
            return yangManageService.personalStatusCommit(personalStatusCommitReqDTO);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 居民最新情况导出
     * @param community  小区
     * @param name  姓名搜索
     * @param status  1-未转运 2-已转运 3-已治愈
     * @return
     */
    @GetMapping("/exportYangPersonal")
    public GeneralResponse exportYangPersonal(@RequestParam(required = false,value = "community") Long community,
                                              @RequestParam(required = false,value = "name") String name,
                                              @RequestParam(required = false,value ="status") Integer status,
                                              HttpServletResponse response) {
        try {
            return yangManageService.exportYangPersonal(community, name, status,response);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 查询阳性居民详情信息
     * @param userId  阳性人员id
     * @return
     */
    @GetMapping("/queryYangPersonalDetails")
    public GeneralResponse<YangPersonalDetailsDTO> queryYangPersonalDetails(@RequestParam("userId") Long userId) {
        try {
            return yangManageService.queryYangPersonalDetails(userId);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }


}
